#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 30;
int n, m, mi = 20;
int a[N], b[N][N];
int c[N], ans[N];

bool pd(int x) {
	for (int i = 1; i <= n; i++) {
		int sum = 0;
		for (int j = 1; j <= m; j++) {
			sum += b[c[j]][i];
		}
		if (sum < a[i]) return false;
	}
	return true;
}

void dfs(int x, int s) {
	if (x > m) {
		if (pd(s) && mi < s) {
			s = mi;
			for (int i = 1; i <= mi; i++) {
				ans[i] = c[i];
			}
		}
		return;
	}
	c[s + 1] = x;
	dfs(x + 1, s + 1);
	dfs(x + 1, s);
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	cin >> m;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> b[i][j];
		}
	}
	dfs(1, 0);
	cout << mi << " ";
	for (int i = 0; i < mi; i++) {
		cout << ans[i] << " ";
	}
	return 0;
}